import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

from common.OpenWeb import OpenWeb

class Card:
    def card_add(self, driver,  username, password, cardname, cardnum):
        driver.find_element(By.ID, "username").send_keys(username)
        driver.find_element(By.ID, "password").send_keys(password)
        driver.find_element(By.ID, "login_btn").click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        driver.find_element(By.XPATH, '//*[@id="bankCard_add_modal_btn"]').click()
        driver.find_element(By.XPATH,
                                  '/html/body/div[1]/div/main/div/div/div[4]/div/div/div[2]/form/div[1]/div[1]/input').send_keys(cardname)
        driver.find_element(By.XPATH,
                                  '/html/body/div[1]/div/main/div/div/div[4]/div/div/div[2]/form/div[3]/div[1]/input').send_keys(cardnum)
        driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div[4]/div/div/div[3]/button[2]').click()
    def card_delete(self, driver,  username, password):
        driver.find_element(By.ID, "username").send_keys(username)
        driver.find_element(By.ID, "password").send_keys(password)
        driver.find_element(By.ID, "login_btn").click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[2]').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
    def card_delect_cancel(self, driver,  username, password):
        driver.find_element(By.ID, "username").send_keys(username)
        driver.find_element(By.ID, "password").send_keys(password)
        driver.find_element(By.ID, "login_btn").click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[2]').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[2]').click()
    def card_update_name(self, driver,  username, password, cardname):
        driver.find_element(By.ID, "username").send_keys(username)
        driver.find_element(By.ID, "password").send_keys(password)
        driver.find_element(By.ID, "login_btn").click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[1]').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '//*[@id="cardBank_update_input"]').clear()
        driver.find_element(By.XPATH, '//*[@id="cardBank_update_input"]').send_keys(cardname)
        driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div[5]/div/div/div[3]/button[2]').click()
    def card_update_num(self, driver,  username, password, cardnum):
        driver.find_element(By.ID, "username").send_keys(username)
        driver.find_element(By.ID, "password").send_keys(password)
        driver.find_element(By.ID, "login_btn").click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[1]').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div[5]/div/div/div[2]/form/div[3]/div[1]/input').clear()
        driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div[5]/div/div/div[2]/form/div[3]/div[1]/input').send_keys(cardnum)
        driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div[5]/div/div/div[3]/button[2]').click()

    def card_update_type(self, driver,  username, password):
        driver.find_element(By.ID, "username").send_keys(username)
        driver.find_element(By.ID, "password").send_keys(password)
        driver.find_element(By.ID, "login_btn").click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        time.sleep(2)
        driver.refresh()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[1]').click()
        time.sleep(2)
        driver.find_element(By.XPATH,
                                  '/html/body/div[1]/div/main/div/div/div[5]/div/div/div[2]/form/div[2]/div[1]/div/label[2]/span').click()
        driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div[5]/div/div/div[3]/button[2]').click()











